package com.xingxing.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.xingxing.Activity.EditPasswordActivity;
import com.xingxing.Activity.EditProfileActivity;
import com.xingxing.Activity.LoginActivity;
import com.xingxing.Activity.databinding.FragmentMeBinding;
import com.xingxing.Util.CommonUtils;

import java.util.Objects;

import static com.xingxing.Util.CommonUtils.GetUserInfo;

public class MeFragment extends Fragment {
    private FragmentMeBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = FragmentMeBinding.inflate(inflater, container, false);
        View root = binding.getRoot();
        binding.tvNickName.setText(Objects.requireNonNull(GetUserInfo()).getNickName());
        CommonUtils.setImageByUrl(binding.headImage, "https://c-ssl.duitang.com/uploads/item/202006/07/20200607210512_rnkiq.jpg");
        binding.editProfile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), EditProfileActivity.class);
                startActivity(intent);
            }
        });
        binding.editPassword.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), EditPasswordActivity.class);
                startActivity(intent);
            }
        });
        binding.btnLogout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), LoginActivity.class);
                startActivity(intent);
                getActivity().finish();
            }
        });
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}